<template>
  <el-dialog title="下载推广码" :visible.sync="dialogVisible" @close='dialogFormVisible' :close-on-click-modal="false"
    :close-on-press-escape="false">
    <el-form size="small" :model="form">
      <el-form-item label="下载类型" :label-width="formLabelWidth">
        <el-radio-group v-model="source">
          <el-radio label="wx">微信小程序</el-radio>
          <el-radio label="mp">公众号，H5网页</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible">取 消</el-button>
      <el-button type="primary" @click="qrcodeClick">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import qs from 'qs';
  export default {
    data() {
      return {
        /*左边长度*/
        formLabelWidth: '120px',
        dialogVisible: false,
        source: 'wx'
      };
    },
    props: ['open_qrcode', 'form'],
    created() {
      this.dialogVisible = this.open_qrcode;
    },
    methods: {
      qrcodeClick(){
        let baseUrl = window.location.protocol + '//' + window.location.host;
        let params = {
          id: this.form.gift_package_id,
          source: this.source
        };
        window.location.href = baseUrl + '/index.php/shop/plus.package/qrcode?' + qs.stringify(params);
      },

      /*关闭弹窗*/
      dialogFormVisible(e) {
        if (e) {
          this.$emit('closeDialog', {
            type: 'success',
            openDialog: false
          })
        } else {
          this.$emit('closeDialog', {
            type: 'error',
            openDialog: false
          })
        }
      }

    }
  };
</script>

<style></style>
